const Toast = require('../../dist/toast/toast');
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    send: false,
    send1: true,
    qu: true,
    qu1: false,
    current: 3, //0送餐 9店内就餐
    id: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var id = options.id
    this.setData({
      id: id
    })
  },
  haha(){
    wx.getStorageInfo({
      success: function (res) {
        console.log(res.key)
      }
    })
  },
  tap(e) {
    let that = this
    let index = e.currentTarget.dataset.id
    console.log(index)
    if (index == 1) {
      return false;
    } else {
      that.setData({
        qu: false,
        qu1: true,
        send: true,
        send1: false,
        current: index
      })
    }
  },
  tap1(e) {
    let that = this
    let index = e.currentTarget.dataset.id
    if (index == 1) {
      return false;
    } else {
      console.log(index)
      that.setData({
        qu: true,
        qu1: false,
        send: false,
        send1: true,
        current: index
      })
    }
  },
  //判断登录状态

  btn_e() {
    let that = this
    if (!app.globalData.userInfo) {
      wx.showModal({
        title: '请先授权登录',
        success(res) {
          if (res.confirm) {
            wx.switchTab({
              url: '../../pages/my/my',
            })
          }
        }
      })
      return false;
    }
    let restaurantId = that.data.id
    let userid = app.globalDataO.openid.objectSid
    let deskId=0
    console.log(userid)
    if (!that.data.current) {
      wx.showToast({
        icon: 'fail',
        title: '请选择就餐方式',
      })
    }
    if (that.data.current == 3) {
      app.post(app.url.DCopenTable, {
        restaurantId: restaurantId,
        memberId: userid,
        deskId: deskId,
        type: 4,
        seats: 0
      }).then(res => {
        console.log(res)
        let bill_id = res.data.bill_id
        console.log(res.data.bill_id)
        wx.navigateTo({
          url: '../../pages/food/food?restaurantId=' + restaurantId + '&types=4' +  '&bill_id=' + bill_id + '&deskId=' + deskId,
        })
      })
 
    }
    if (that.data.current == 2) {
      wx.navigateTo({
        url: '../../pages/select_table/select_table?restaurantId=' + restaurantId + '&types=' + that.data.current
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})